// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024.
 * Description:sysmonitor:add signal notifier call chain
 * Author: hanhuihui
 * Create: 2024-4-23
 */
#include <linux/sysmonitor-signal.h>

ATOMIC_NOTIFIER_HEAD(send_sig_info_notifier_list);

void sysmonitor_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p, int type)
{
	send_sig_info_data_t notifier_call_data = {
		.sig = sig,
		.info = info,
		.p = p,
		.group = type,
	};
	(void)atomic_notifier_call_chain(&send_sig_info_notifier_list, 0,
					(void *)(&notifier_call_data));
}

int register_signo_catch_notifier(struct notifier_block *nb)
{
	if (nb == NULL) {
		pr_err("register signo catch notification failed. nb is NULL\n");
		return -EINVAL;
	}

	if (nb->notifier_call == NULL) {
		pr_err("register signo catch notification failed. notifier_call is NULL\n");
		return -EINVAL;
	}

	return atomic_notifier_chain_register(&send_sig_info_notifier_list, nb);
}
EXPORT_SYMBOL(register_signo_catch_notifier);

int unregister_signo_catch_notifier(struct notifier_block *nb)
{
	if (nb == NULL) {
		pr_err("unregister signo catch notification failed. nb is NULL\n");
		return -EINVAL;
	}

	return atomic_notifier_chain_unregister(&send_sig_info_notifier_list, nb);
}
EXPORT_SYMBOL(unregister_signo_catch_notifier);
